/**
 * Created by Administrator on 2017/7/14.
 */


global.logger = require('pomelo-logger').getLogger('hall');
var GlobalConfig = require('../../../config/config.json');

global.DB = require('../../util/mongodb.js');

var RankManager = require('./rankManager').RankManager;

global.gRankManager = new RankManager();

var systemConfig = require('../../../config/systemConfig.json');

module.exports = {
    init: function() {
        async.series([
            function(cb) {
                DB.loadDB(function(err) {
                    if (err) {
                        logger.error("db load failed: %j", err);
                    }
                    cb(err);
                });
            },
            function(cb) {
                DB.initDB(function(err) {
                    if (err) {
                        logger.error("db init failed: %j", err);
                    }
                    cb(err);
                });
            },
            function(cb) {
                gRankManager.init(cb);
            },
            function(cb) {
                gRankManager.update(cb);
            }
        ], function(err) {
            if (err) {
                logger.error("hall init failed: %j", err);
                process.exit(-1);
            }

            setInterval(function() {
                gRankManager.update(function() {});
            }, systemConfig["RankManage"]["setIntervalTime"]);

            logger.info('hall init success');
        });
    },

    stop: function(callback) {
        async.series([
            function(cb) {
                cb();
            }
        ], function(err) {
            logger.info('hall stop success');
            callback && callback();
        });
    }
}